package com.iss.ljx.department.control;


import com.iss.ljx.department.entity.DepartmentEntity;
import com.iss.ljx.department.service.DepartmentService;
import com.iss.ljx.mybatis.entity.PtDutyEntity;
import com.iss.ljx.mybatis.flexigrid.PadingRstType;
import com.iss.ljx.mybatis.flexigrid.PagingBean;
import com.iss.ljx.spring.controller.BaseController;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;


@Controller
@RequestMapping("/department")
public class DepartmentController extends BaseController {

    @Resource
    private DepartmentService departmentService;
    @Resource
    private MessageSource messageSource;
    @RequestMapping("/departmentPage")
    public String departmentPage(){
        return "department/departmentPage";
    }
    @RequestMapping("/selectAll")
    @ResponseBody
    public PadingRstType<DepartmentEntity> selectAll(PagingBean paging){
        PadingRstType<DepartmentEntity> padingRstType=departmentService.selectAll(paging);
        return padingRstType;
    }

    @RequestMapping("/selectOneByBranchName")
    @ResponseBody
    public DepartmentEntity selectOneByBranchName(String branchName){
        return departmentService.selectOneByBranchName(branchName);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public String insert(String organUuid, String branchName, String belongCenter,String modifierId, String remark){
//        String depUuid= UUID.randomUUID().toString();
//        Date date = new Date();
//        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
//        String modTime=dateFormat.format(date);
//        departmentService.insert(depUuid,organUuid,branchName,belongCenter,modifierId,modTime,remark);
        return getSuccessMsg("department.insert.success");
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public String deleteById(@RequestParam("depUuid") String depUuid){
        departmentService.deleteById(depUuid);
        return getSuccessMsg("department.delete.success");
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(String depUuid,String organUuid, String branchName, String belongCenter,String modifierId, String remark){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        String modTime=dateFormat.format(date);
        departmentService.update(depUuid,organUuid,branchName,belongCenter,modifierId,modTime,remark);
        return getSuccessMsg("department.update.success");
    }

}

